<script setup>
import { ref } from 'vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const taskTitle = ref('')
const taskDescription = ref('')
const taskReward = ref('')
const difficulty = ref('normal')
const publishedTasks = ref([])

const publishTask = () => {
  const newTask = {
    id: Date.now(),
    title: taskTitle.value,
    description: taskDescription.value,
    reward: taskReward.value,
    difficulty: difficulty.value,
    status: 'active'
  }
  publishedTasks.value.push(newTask)
  resetForm()
}

const resetForm = () => {
  taskTitle.value = ''
  taskDescription.value = ''
  taskReward.value = ''
  difficulty.value = 'normal'
}

const completeTask = (taskId) => {
  const task = publishedTasks.value.find(t => t.id === taskId)
  if (task) {
    task.status = 'completed'
  }
}
</script>

<template>
  <div class="min-h-screen bg-gradient-to-b from-purple-900 to-blue-900 text-white">
    <div class="container mx-auto px-4 py-8">
      <h1 class="text-4xl font-bold text-center mb-8">系统管理面板</h1>
      
      <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
        <!-- 任务发布区 -->
        <div class="bg-gray-800 bg-opacity-70 rounded-lg p-6">
          <h2 class="text-2xl font-bold mb-4">发布新任务</h2>
          
          <div class="space-y-4">
            <div>
              <label class="block text-gray-300 mb-2">任务标题</label>
              <input 
                v-model="taskTitle"
                class="w-full bg-gray-700 text-white p-2 rounded"
                placeholder="请输入任务标题"
              >
            </div>
            
            <div>
              <label class="block text-gray-300 mb-2">任务描述</label>
              <textarea 
                v-model="taskDescription"
                class="w-full h-32 bg-gray-700 text-white p-2 rounded"
                placeholder="详细描述任务内容"
              ></textarea>
            </div>
            
            <div>
              <label class="block text-gray-300 mb-2">任务奖励</label>
              <input 
                v-model="taskReward"
                class="w-full bg-gray-700 text-white p-2 rounded"
                placeholder="例如: 原石x100, 摩拉x50000"
              >
            </div>
            
            <div>
              <label class="block text-gray-300 mb-2">难度级别</label>
              <select 
                v-model="difficulty"
                class="w-full bg-gray-700 text-white p-2 rounded"
              >
                <option value="easy">简单</option>
                <option value="normal">普通</option>
                <option value="hard">困难</option>
                <option value="extreme">极难</option>
              </select>
            </div>
            
            <button 
              @click="publishTask"
              class="bg-purple-600 hover:bg-purple-500 text-white font-bold py-2 px-4 rounded transition"
            >
              发布任务
            </button>
          </div>
        </div>

        <!-- 任务列表区 -->
        <div class="bg-gray-800 bg-opacity-70 rounded-lg p-6">
          <h2 class="text-2xl font-bold mb-4">已发布任务</h2>
          
          <div v-if="publishedTasks.length === 0" class="text-gray-400 text-center py-8">
            暂无已发布任务
          </div>
          
          <div 
            v-for="task in publishedTasks" 
            :key="task.id"
            class="bg-gray-700 rounded-lg p-4 mb-4"
            :class="{
              'border-l-4 border-green-500': task.status === 'completed',
              'border-l-4 border-yellow-500': task.status === 'active'
            }"
          >
            <div class="flex justify-between items-start">
              <div>
                <h3 class="text-xl font-semibold">{{ task.title }}</h3>
                <p class="text-gray-300 mt-1">{{ task.description }}</p>
                <div class="mt-2">
                  <span class="inline-block bg-blue-600 text-white text-xs px-2 py-1 rounded mr-2">
                    {{ 
                      task.difficulty === 'easy' ? '简单' :
                      task.difficulty === 'normal' ? '普通' :
                      task.difficulty === 'hard' ? '困难' : '极难'
                    }}
                  </span>
                  <span class="text-yellow-400">{{ task.reward }}</span>
                </div>
              </div>
              
              <button 
                v-if="task.status === 'active'"
                @click="completeTask(task.id)"
                class="bg-green-600 hover:bg-green-500 text-white text-sm py-1 px-2 rounded transition"
              >
                标记完成
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>